# -*- coding : utf_8 -*-
"""
=======================================
Time : 2025/4/12 18:52
Author : 田霄汉
Email : 522989570@qq.com
File : random_util.py
Project : pytest_demo
=======================================
"""

import random

class RandomUtil:

    def creat_randcode(self, n):
        """
        生成n位随机码，至少包含一位大写英文，一位小写英文，一位数字
        :param n: 大于等于3的数字
        :return: 随机码
        """
        WORDS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
        words = 'abcdefghijklmnopqrstuvwxyz'
        Numbers = '1234567890'
        try:
            x = random.randint(1, n-2)
            y = random.randint(1, n-x-1)
            z = n-x-y
            rand_WORD = random.choices(WORDS, k=x)
            rand_word = random.choices(words, k=y)
            rand_Num = random.choices(Numbers, k=z)
            result = []
            result.extend(rand_WORD)
            result.extend(rand_word)
            result.extend(rand_Num)
            random.shuffle(result)
            code = ''
            for i in result:
                if isinstance(i, int):
                    i = str(i)
                code += i
            return code

        except Exception as E:
            print(f'报错信息：{E}')
